#pragma once
#include "CGIPrefix.h"
#include "CGIResource.h"
#include "Runtime/Utils/SmartPtr.h"

namespace Alice{
    class DynamicCGI{
    public:
        virtual bool Init() = 0;
        virtual DynamicCGI* GetNonValidationRHI() { return this; }
        //  must be called from the main thread.
        // FlushType: Thread safe
        virtual SmartPtr<CGIViewport> CGICreateViewport(void* WindowHandle, uint32 SizeX, uint32 SizeY, bool bIsFullscreen, EPixelFormat PreferredPixelFormat) = 0;
        virtual SmartPtr<CGITexture> CGIGetViewportBackBuffer(CGIViewport* Viewport) = 0;
    };
}
extern Alice::DynamicCGI*gDynamicCGI;
template<typename TCGI>
FORCEINLINE TCGI* CastDynamicRHI(Alice::DynamicCGI* InDynamicRHI)
{
    return static_cast<TCGI*>(InDynamicRHI->GetNonValidationRHI());
}
template<typename TCGI>
FORCEINLINE TCGI* GetDynamicRHI()
{
    return CastDynamicRHI<TCGI>(gDynamicCGI);
}
extern "C" void CGIInit();
FORCEINLINE Alice::SmartPtr<Alice::CGIViewport> CGICreateViewport(void* WindowHandle, uint32 SizeX, uint32 SizeY, bool bIsFullscreen, Alice::EPixelFormat PreferredPixelFormat)
{
    return gDynamicCGI->CGICreateViewport(WindowHandle, SizeX, SizeY, bIsFullscreen, PreferredPixelFormat);
}
FORCEINLINE Alice::SmartPtr<Alice::CGITexture> RHIGetViewportBackBuffer(Alice::CGIViewport* Viewport)
{
    return gDynamicCGI->CGIGetViewportBackBuffer(Viewport);
}
Alice::DynamicCGI* PlatformCreateDynamicCGI();